import java.util.Formatter;

/**
 * Enforces 60-second termination of the program.
 * This is only reset at the start/end of every action.
 * This route was taken not to pollute the code as much.
 */
public class DVDTimer extends Thread {
	private int durationMS;
	private long timeoutMS;
	/**
	 * Create a new DVD timer thread
	 * @param ms duration
	 */
	public DVDTimer(int ms) {
		durationMS = ms;
		resetTimer();
	}
	/**
	 * Reset the time out counter
	 */
	synchronized public void resetTimer(){
		timeoutMS = System.currentTimeMillis() + durationMS;
	}
	/**
	 * Get the time out target time
	 * @return time out time in ms
	 */
	synchronized public long getTimeout(){
		return timeoutMS;
	}
	/**
	 * Run the timer loop
	 */
	public void run() {
		while ( true){
			if (System.currentTimeMillis() > getTimeout()){
				System.out.println("Your session has timed out.");
				System.exit(0);
			}
		}
	}
	
}